<?php
/**
 * @file NoticeCore.class.php
 * @author LD <2009-11-05 15:39:45>
 * @package notice
 * @desc
 *   所有公告内部东东...
 */
require_once '_code/config/db_name_config.inc.php';
global $Options; //全局变量
$Options = array(
	'newsUrl' => "notice/index.php", //公告页
	'helpUrl' => "notice/index.php?controller=help&action=faq", //帮助页
	'partyUrl' => "notice/index.php?controller=party&action=list", //房间活动
	'catNums' => array(2, 1, 3, 13, 14, 15), //分类D数字
);

/**
 * 公告核心数据调用、公有函数...
 *
 */
class NoticeCore{
	private static $instance = NULL; //MySQLi静态对象
	public $mysqli;

	private function __construct(){}
	public function __destruct(){
		if (self::$instance->mysqli)
			self::$instance->mysqli->close();
	}
	
	/**
	 * 获取MySQLi静态对象
	 * @return object
	 */
	public static function getInstance(){
		if (self::$instance == NULL){
			self::$instance = new NoticeCore();
			self::$instance->mysqli = new mysqli($_SERVER['kkyooDB_HOST'],$_SERVER["kkyooDB_NAME"],$_SERVER["kkyooDB_PASS"]);
			if (!self::$instance->mysqli) {
				die('Could not connect: ' . mysqli_connect_error());
			}
			/*if ( !self::$instance->mysqli->select_db(DB_NAME) ) {
				die('Could not select database: '.mysqli_error());
			}
			*/self::$instance->mysqli->query("SET NAMES utf8 ;");
		}
		return self::$instance;
	}//END func getInstance

	/**
	 * 执行输入的SQL语句,返回一位数组
	 *
	 * @param String $query
	 * @return array
	 */
	public static function sql2Arr($query){
		$mysqli = self::getInstance()->mysqli;
		$re = $mysqli->query($query);
		
		if (is_object($re)){
			$row = $re->fetch_assoc();
			$mysqli->next_result();
		}
		
		return $row;
	}//END func executeSQL

	/**
	 * 执行输入的SQL语句,返回二维数组
	 *
	 * @param String $query
	 * @return array
	 */
	public static function sql2Arrs($query){
		$mysqli = self::getInstance()->mysqli;
		$re = $mysqli->query($query);
		
		if (is_object($re)){
			$arr = array();
			while ( $row = $re->fetch_assoc() ){
				array_push($arr, $row);
			}
			$mysqli->next_result();
		}
		
		return $arr;
	}//END func executeSQL
	
}//END class NoticeCore
?>